package com.zy.rpc.common.Serializer.impl;

import com.alibaba.fastjson.JSON;
import com.zy.rpc.common.Serializer.Serializer;

import java.nio.charset.StandardCharsets;

/**
 * @author zy
 * @date 2023/5/24 18:41
 */
public class JsonSerializer implements Serializer {
    @Override
    public <T> T deserialize(Class<T> clazz, byte[] bytes) {

        return JSON.parseObject(bytes, clazz);
    }

    @Override
    public <T> byte[] serialize(T object) {
        String jsonString = JSON.toJSONString(object);
        return jsonString.getBytes(StandardCharsets.UTF_8);
    }
}
